// console.log('lixingxxl');
// io 是 websocket的封装 new websocket(ws：//locahost:1234)
// socket 框架
let socket=io();
socket.on('connect',()=>{
    console.log('服务器连接成功');
})


socket.on('message',data=>{
    let li=document.createElement('li');
    li.className='list-group-item';
    li.innerHTML=`
    <p style="color:#ccc;>
        <span class="user">${data.user}</span>
        ${data.createAt}
    </p>
    <p class="content">${data.content}</p>
    `;
    list.appendChild(li);
})

let list = document.getElementById('list'),
    input=document.getElementById('input'),
    sendBtn=document.getElementById('sendBtn');

function send(){
    let value=input.value.trim();
    if(value){
        socket.emit('message',value);
        input.value='';
    }else{
        alert('内容不能为空');
    }
}
sendBtn.onclick=send;